import time

from selenium.webdriver.common.by import By

from base.app_base_page import AppBasePage


class PagePay(AppBasePage):
    def __init__(self, driver):
        super().__init__(driver)
        self.__buy_btn = (By.ID, "com.tpshop.malls:id/buy_tv")
        self.__submit_btn = (By.XPATH, "//*[@text='提交订单']")
        self.__pay_btn = (By.XPATH, "//*[@text='立即支付']")
        self.__pwd_et = (By.ID, "com.tpshop.malls:id/pwd_et")
        self.__ok_btn = (By.XPATH, "//*[@text='确定']")
        self.__pay_success = (By.ID, "com.tpshop.malls:id/title_tv")

    def page_pay(self, text="abc123"):
        self.app_base_click(self.__buy_btn)
        self.app_base_click(self.__submit_btn)
        self.app_base_click(self.__pay_btn)
        self.app_base_send_keys(self.__pwd_et, text)
        self.app_base_click(self.__ok_btn)

    def get_pay_success(self):
        time.sleep(1)
        return self.app_fd_element(self.__pay_success).text
